package com.xinlong.controller;

import com.xinlong.entity.Route;
import com.xinlong.entity.product;
import com.xinlong.service.IRouteService;
import com.xinlong.service.impl.RouteServiceimpl;
import com.xinlong.service.impl.productserviceimpl;
import com.xinlong.service.productservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/Route")
public class Routecontriller {

    @Autowired
    IRouteService  selectRoute;

    @Autowired
    productservice productive;

    @RequestMapping("/selectRoute.do")
    public ModelAndView selectRoute() {
        ModelAndView mv=new ModelAndView();
        List<Route> routes=selectRoute.selectRoute();
        mv.addObject("RouteList",routes);
        mv.setViewName("Route-list");
        return mv;
    }

    @RequestMapping("/selectRoutebyid.do")
    public ModelAndView selectRoutebyid(Integer id) throws Exception {
        ModelAndView mv=new ModelAndView();
        Route routes=selectRoute.selectRoutebyid(id);
        mv.addObject("RouteList",routes);
        List<product> productList= productive.productSelect();
        mv.addObject("productList",productList);
        mv.setViewName("Route-update");
        return mv;
    }

    @RequestMapping("/opensevaRoute.do")
    public ModelAndView opensevaRoute() throws Exception {
        ModelAndView mv=new ModelAndView();
        List<product> productList= productive.productSelect();
        mv.addObject("productList",productList);
        mv.setViewName("Route-add");
        return mv;
    }

    @RequestMapping("/sevaRoute.do")
    public String sevaRoute(Route route) {
        selectRoute.sevaRoute(route);
        return "redirect:selectRoute.do";
    }



    @RequestMapping("/deRoute.do")
    public String deRoute(Integer id) {
        selectRoute.deRoute(id);
        return "redirect:selectRoute.do";
    }

    @RequestMapping("/upRoute.do")
    public String upRoute(Route route) {
        selectRoute.upRoute(route);

        return "redirect:selectRoute.do";
    }


}
